package city.spring.modules.medicalstation.doctorsOrderItem.service.impl;

import city.spring.modules.medicalstation.doctorsOrderItem.entity.DoctorsOrderItemEntity;
import city.spring.modules.medicalstation.doctorsOrderItem.repository.DoctorsOrderItemRepository;
import city.spring.modules.medicalstation.doctorsOrderItem.service.DoctorsOrderItemService;
import city.spring.modules.medicalstation.doctorsOrderItem.vo.DoctorsOrderItemVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service：医嘱项目
 *
 * @author 谢金婷
 * @date 2020-10-29 10:57:28
 */
@CacheConfig(cacheNames = {DoctorsOrderItemServiceImpl.CACHE_NAME})
@Transactional(rollbackFor = Exception.class)
@Service
public class DoctorsOrderItemServiceImpl extends ServiceImpl<DoctorsOrderItemRepository, DoctorsOrderItemEntity> implements DoctorsOrderItemService {

    private final DoctorsOrderItemRepository doctorsOrderItemRepository;

    public DoctorsOrderItemServiceImpl(DoctorsOrderItemRepository doctorsOrderItemRepository) {
        this.doctorsOrderItemRepository = doctorsOrderItemRepository;
    }

    @Override
    public void saveDoctorsOrderItem(DoctorsOrderItemEntity entity) {
        if (!save(entity)) {
            throw new RuntimeException("保存信息失败");
        }
    }

    @Override
    public void updateDoctorsOrderItem(DoctorsOrderItemEntity entity) {
        // 使用 updateById(entity); 修改数据时，将会修改 entity 对象中所有非null数据，如果某个字段为null，将会忽略该字段的修改
        if (!updateById(entity)) {
            throw new RuntimeException("修改信息失败");
        }
    }

    @Override
    public void deleteDoctorsOrderItem(String primaryKey) {
        removeById(primaryKey);
    }

    @Override
    public void deleteDoctorsOrderItem(List<String> primaryKeys) {
        removeByIds(primaryKeys);
    }

    @Override
    public IPage<DoctorsOrderItemVO> listPage(Page<? extends DoctorsOrderItemEntity> page, Wrapper<? extends DoctorsOrderItemEntity> wrapper) {
        return baseMapper.listPage(page, wrapper);
    }

    @Override
    public IPage<DoctorsOrderItemVO> druglistPage(Page<? extends DoctorsOrderItemEntity> page, Wrapper<? extends DoctorsOrderItemEntity> wrapper) {
        return baseMapper.druglistPage(page, wrapper);
    }

    @Override
    public List<DoctorsOrderItemEntity> getByType(String type) {
        return doctorsOrderItemRepository.getByType(type);
    }
}